<?php require_once('../Connections/CrossFit.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_CheckUserName = "-1";
if (isset($_POST['Username'])) {
  $colname_CheckUserName = $_POST['Username'];
}
mysql_select_db($database_CrossFit, $CrossFit);
$query_CheckUserName = sprintf("SELECT ID, Username FROM Login WHERE Username = %s", GetSQLValueString($colname_CheckUserName, "text"));
$CheckUserName = mysql_query($query_CheckUserName, $CrossFit) or die(mysql_error());
$row_CheckUserName = mysql_fetch_assoc($CheckUserName);
$totalRows_CheckUserName = mysql_num_rows($CheckUserName);

if ($row_CheckUserName['Username'] <> $_POST['Username']) {
	
	header("Location: http://development.crossfit26.com/app/registration?message='You do not have a login to reset a password for, try registering!'");
}
else {


##Send activation Email to User

$to      = $_POST['Username'];
$User_ID = $row_CheckUserName['ID'] ;
$subject = "CrossFit 26 Member Password Reset";

$message = "Seriously? Is this why you never remember how many rounds you did? \r\rYou can reset your password by clicking the following link:\rhttp://development.crossfit26.com/app/set-new-password?coyote=$User_ID\r\rIf you have recieved this message erroneously, please contact ryan@crossfit26.com.\r\rRegards, the CrossFit 26 Team";

$headers = 'From: ryan@crossfit26.com' . "\r\n";

    

mail($to, $subject, $message, $headers);


  $deleteGoTo = "http://development.crossfit26.com/app/pending-password-reset/";
  
  
  header(sprintf("Location: %s", $deleteGoTo));
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Reset Password</title>
</head>

<body>
<center><img src="ajax-loader.gif" width="32" height="32" style="margin-top:150px;"><p>Processing...</p>

<p>
 
</p>
</center>

<script type="text/javascript">
<!--
//window.location = "http://development.crossfit26.com/app"
//-->
</script>


</body>
</html>
<?php
mysql_free_result($CheckUserName);
?>
